home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 18 / CU Amiga Magazine's Super CD-ROM 18 (1997)(EMAP Images)(GB)[!][issue 1998-01].iso / CUCD / Online / hsc / source / ugly / uargs.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-11-02  |  6.2 KB  |  202 lines

  1. /*
  2.  * This source code is part of hsc, a html-preprocessor,
  3.  * Copyright (C) 1993-1997  Thomas Aglassinger
  4.  *
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or
  8.  * (at your option) any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  */
  20. /*
  21.  * ugly/uargs.h
  22.  *
  23.  * ugly argument handling functions, header file
  24.  *
  25.  */
  26.  
  27. #ifndef UGLY_UARGS_H
  28. #define UGLY_UARGS_H
  29.  
  30. /*
  31.  * includes
  32.  */
  33. #include <stdio.h>
  34. #include <stdarg.h>
  35.  
  36. #include "utypes.h"
  37. #include "umemory.h"
  38.  
  39. /*
  40.  * argument errors (returned by _set_args())
  41.  */
  42. #define ASE_NO_MEM                0x01  /* out of memory */
  43. #define ASE_INVALID_NUM           0x02  /* invalid number format */
  44. #define ASE_REQUIRED_MISS         0x03  /* required argument missing */
  45. #define ASE_OUT_OF_RANGE          0x04  /* out of range (LONG, ULONG) */
  46. #define ASE_INVALID_ENUM          0x05  /* invalid enum identifier (ENUM) */
  47. #define ASE_EMPTY_TEMPLATE        0x06  /* empty template (arglist==NULL) */
  48. #define ASE_UNKNOWN_KEYWORD       0x07  /* unknown keyword */
  49. #define ASE_OCCURED_TWICE         0x08  /* arg w/o /O or /M occured twice */
  50. #define ASE_NO_VAL_AFTER_KW       0x09  /* value after keyword missing */
  51.  
  52. #define ASE_HANDLE_FUNC           0x7f  /* error reported by handle func */
  53.  
  54. /*
  55.  * argument errors (returned by _prep_args())
  56.  */
  57. #define APE_NO_MEM                0x01  /* out of memory */
  58. #define APE_INVALID_TEMPLATE      0x02  /* invalid template */
  59. #define APE_DOUBLE_TEMPLATE       0x03  /* doubel definition of template */
  60. #define APE_EMPTY_TEMPLATE        0x04  /* empty template */
  61. #define APE_ILLEGAL_TYPE          0x05  /* unknown type */
  62. #define APE_ILLEGAL_FLAG          0x06  /* unknown flag */
  63. #define APE_DESTVAR_IS_NULL       0x07  /* destination var is NULL */
  64. #define APE_DOUBLE_MULTIPLE       0x08  /* /M used twice */
  65. #define APE_CONFLICTING_M_O       0x09  /* /M and /O both occured */
  66.  
  67. /*
  68.  * argument types
  69.  */
  70. #define ARG_SWITCH     0x01     /* S */
  71. #define ARG_TEXT       0x02     /* T */
  72. #define ARG_LONG       0x03     /* L */
  73. #define ARG_LONG_RANGE 0x04     /* R */
  74. #define ARG_ENUM       0x05     /* E */
  75. #define ARG_ULONG      0x06     /* U */
  76.  
  77. /*
  78.  * argument flags
  79.  */
  80. #define ARG_KEYWORD         ( 1 << 0 )  /* K */
  81. #define ARG_REQUIRED        ( 1 << 1 )  /* R */
  82. #define ARG_MULTIPLE        ( 1 << 2 )  /* M */
  83. #define ARG_CASESENS        ( 1 << 3 )  /* C - case sensitive */
  84. #define ARG_OVERWRITE       ( 1 << 4 )  /* O - overwrite old value when */
  85.                                        /*     occurend more then once */
  86. #define ARG_HANDLEFUNC      ( 1 << 5 )  /* $ */
  87.  
  88. /* values for arginfo.ai_set */
  89. #define AIS_UNSET        0 /* not set at all */
  90. #define AIS_SET_PREVIOUS 1 /* set by previous set_args() */
  91. #define AIS_SET_LOCAL    2 /* set by current set_args() */
  92.  
  93. /*
  94.  * struct arginfo (PRIVATE,DON NOT USE)
  95.  */
  96. typedef struct arginfo
  97. {
  98.     STRPTR ai_id;               /* arg id string */
  99.     LONG ai_type;               /* arg type */
  100.     LONG ai_flags;              /* arg flags */
  101.     union
  102.     {
  103.         STRPTR ai_enum;         /*   enumerator string */
  104.         LONG ai_lolim;          /*   lower limit for range */
  105.     }
  106.     ai_misc1;                   /* type depending information */
  107.     union
  108.     {
  109.         LONG ai_uplim;          /*   upper limit for range */
  110.     }
  111.     ai_misc2;                   /* type depending information */
  112.     APTR ai_dest;               /* ptr to destination var */
  113.       STRPTR(*ai_func) (STRPTR);        /* additional arg handling function */
  114.     STRPTR ai_help;             /* help text */
  115.     BOOL ai_set;                /* handled by _set_args() */
  116. } ARGINFO;
  117.  
  118. typedef struct argfile
  119. {
  120.     int argc;
  121.     char **argv;
  122. } ARGFILE;
  123.  
  124. /*
  125.  * commments about ARGINFO
  126.  *
  127.  * handle function:
  128.  *   the handle function is called by set_arg_value() AFTER the
  129.  *   destination var is updated. the old value is passed as an
  130.  *   APTR to the handle. the handle should return a ptr to a
  131.  *   string that contains an error message or NULL if the new
  132.  *   arg is ok.
  133.  *
  134.  *   example for a handle function for numeric args
  135.  *   STRPTR handle_func( STRPTR newval )
  136.  *   {
  137.  *       STRPTR errmsg = NULL;
  138.  *
  139.  *       printf( "handle_func: set val to %d", newval );
  140.  *       if ( newval > 3 )
  141.  *          errmsg = "val to high!\n";
  142.  *       else if ( newval < 1 )
  143.  *          errmsg = "val to low!\n";
  144.  *
  145.  *       return ( errmsg );
  146.  *   }
  147.  */
  148.  
  149. /*
  150.  * struct arglist (PRIVATE)
  151.  */
  152. typedef struct arglist
  153. {
  154.     STRPTR al_name;             /* name (only for debugging) */
  155.     struct dllist *al_list;     /* argument template */
  156.     struct arginfo *al_multiple;        /* entry with /M flag set */
  157.     struct arginfo *al_nokeywd; /* entry w/o /K flag; TODO: remove */
  158. } ARGLIST;
  159.  
  160. /* debuggin define */
  161. #if DEBUG_UGLY_ARG
  162. #define DA(x) x
  163. #define DUA "*args  * "
  164. #else
  165. #define DA(x)                   /* nufin */
  166. #define DUA                     /* nufin */
  167. #endif
  168.  
  169. /*
  170.  * extern functions & global vars
  171.  */
  172.  
  173. #ifndef NOEXTERN_UGLY_UARGS_H
  174.  
  175. extern LONG prep_error_num;
  176. extern int prep_error_idx;
  177. extern size_t prep_error_pos;
  178.  
  179. extern ARGLIST *prepare_args(STRPTR arglist_name,...);
  180. extern BOOL set_args(int argc, char *argv[], ARGLIST *al);
  181. extern BOOL set_args_argv(int argc, char *argv[], ARGLIST * al);
  182. extern BOOL set_args_file(ARGFILE *argf, ARGLIST *argl);
  183. extern VOID free_args(ARGLIST *al);
  184. extern BOOL check_args(ARGLIST *al);
  185.  
  186. extern ARGFILE *new_argfile(char *argfname);
  187. extern ARGFILE *new_argfilev(STRPTR fname[]);
  188. extern VOID del_argfile(ARGFILE *argf);
  189.  
  190. /* display help */
  191. extern int fprintf_arghelp(FILE * stream, ARGLIST *al);
  192. extern int fprintf_arghelp_short(FILE * stream, ARGLIST *al);
  193.  
  194. /* error handling */
  195. extern STRPTR strargerr(VOID);
  196. extern void pargerr(VOID);
  197.  
  198. #endif /* NOEXTERN_UGLY_UARGS_H */
  199.  
  200. #endif /* UGLY_UARGS_H */
  201.  
  202.